#ifndef __EXEC_HELPER_H__
#define __EXEC_HELPER_H__

#include "cpu/helper.h"
#include "cpu/decode/decode.h"

#define make_helper_v(name) \
	make_helper(concat(name, _v)) { \
		return (ops_decoded.is_operand_size_16 ? concat(name, _w) : concat(name, _l)) (eip); \
	}
//mov.c中用

//调用：
//make_helper_v(mov_i2r)
//宏展开后形如：
// int mov_i2r_v(swaddr_t eip){ 
//     return (ops_decoded.is_operand_size_16 ? mov_i2r_w : mov_i2r_l) (eip); 
// }


#define do_execute concat4(do_, instr, _, SUFFIX)		//SUFFIX值由DATA_BYTE决定


#define make_instr_helper(type) \
	make_helper(concat5(instr, _, type, _, SUFFIX)) { \
		return idex(eip, concat4(decode_, type, _, SUFFIX), do_execute); \
	}

//mov-template.h中用

//调用：
//make_instr_helper(i2r)
//宏展开后形如：
// int mov_i2r_l (swaddr_t eip) {
// return idex(eip, decode_i2r_l, do_mov_l);
// }
//idex中先调用decode_i2r_l(eip + 1)		在decode-template.h
//后调用do_mov_l()		在mov-template.h



extern char assembly[];
#ifdef DEBUG
#define print_asm(...) Assert(snprintf(assembly, 80, __VA_ARGS__) < 80, "buffer overflow!")
#else
#define print_asm(...)
#endif

#define print_asm_template1() \
	print_asm(str(instr) str(SUFFIX) " %s", op_src->str)

#define print_asm_template2() \
	print_asm(str(instr) str(SUFFIX) " %s,%s", op_src->str, op_dest->str)

#define print_asm_template3() \
	print_asm(str(instr) str(SUFFIX) " %s,%s,%s", op_src->str, op_src2->str, op_dest->str)

#endif
